#include "stm32f10x.h"                  // Device header

uint8_t striked=0;

void Infrared_Init(void){
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	
	//配置GPIO
	GPIO_InitTypeDef gpioType;
	gpioType.GPIO_Mode=GPIO_Mode_IPU;
	gpioType.GPIO_Pin=GPIO_Pin_1;
	gpioType.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&gpioType);
	
	//配置afio，外部中断引脚选择
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1);
	
	//配置exti
	EXTI_InitTypeDef extiType;
	extiType.EXTI_Line=EXTI_Line1;
	extiType.EXTI_LineCmd=ENABLE;
	extiType.EXTI_Mode=EXTI_Mode_Interrupt;
	extiType.EXTI_Trigger=EXTI_Trigger_Rising_Falling;
	EXTI_Init(&extiType);
	
	//配置NVIC
	NVIC_InitTypeDef nvicType;
	nvicType.NVIC_IRQChannel=EXTI1_IRQn;
	nvicType.NVIC_IRQChannelCmd=ENABLE;
	nvicType.NVIC_IRQChannelPreemptionPriority=1;
	nvicType.NVIC_IRQChannelSubPriority=1;
	NVIC_Init(&nvicType);
}

uint8_t Get_Striked(void){
	return striked;
}

void EXTI1_IRQHandler(void){
	if (EXTI_GetITStatus(EXTI_Line1) == SET)		//判断是否是外部中断1号线触发的中断
	{
		/*判断引脚电平*/
		if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) == 0){//低电平表示有遮挡
			striked=1;					
		}else{
			striked=0;	
		}
		EXTI_ClearITPendingBit(EXTI_Line1);		//清除外部中断1号线的中断标志位
													//中断标志位必须清除
													//否则中断将连续不断地触发，导致主程序卡死
	}
}
